package cn.deluxelx.im.service;

import cn.deluxelx.im.dao.MessageDAO;
import cn.deluxelx.im.pojo.Message;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MessageService {

    @Resource
    private MessageDAO messageDAO;

    public List<Message> queryMessageList(Long fromId, Long toId, Integer page, Integer rows) {
        List<Message> list = messageDAO.findListByFromAndTo(fromId, toId, page, rows);
        for (Message message: list) {
            if (message.getStatus() == 0) {
                // 修改消息状态为已读
                messageDAO.updateMessageState(message.getId(), 1);
            }
        }
        return list;
    }

}
